home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / CONTRSRC.ZIP / SRC / MORFLAME / 320X200.INC next >
Encoding:
Text File  |  1994-11-11  |  12.8 KB  |  368 lines

  1. ; ------------------------------------------------------
  2. ; Module Graphique (Mode X) 320x200 256 couleurs (60Hz)
  3. ; programmation : Morflame (Septembre 1994)
  4. ; Utilise le gourou mode de Type One [Tfl]
  5. ; ------------------------------------------------------
  6.                               
  7. ; ===  - Valeurs registres VGA -  ===
  8.                               
  9. VGA_Segment     EQU     0A000h                ; Segment mémoire vga
  10. ATTRIB_Ctrl     EQU     03C0h                 ; Contrôleur d'attribut VGA 
  11. GC_Index        EQU     03CEh                 ; Contrôleur graphique VGA 
  12. SC_Index        EQU     03C4h                 ; Contrôleur séquenceur VGA
  13. SC_Data         EQU     03C5h                 ; Port de données séq. VGA
  14. CRTC_Index      EQU     03D4h                 ; Contrôleur crt VGA
  15. CRTC_Data       EQU     03D5h                 ; Contrôleur données crt VGA
  16. MISC_OUTPUT     EQU     03C2h                 ; Registre VGA divers
  17. INPUT_1         EQU     03DAh                 ; Registre statut d'input #1
  18.                               
  19. DAC_WRITE_ADDR  EQU     03C8h                 ; Reg addr écriture DAVGA
  20. DAC_READ_ADDR   EQU     03C7h                 ; Reg addr lecture DAVGA
  21. PEL_DATA_REG    EQU     03C9h                 ; Reg données R/W DAC/PEL VGA
  22. PIXEL_PAN_REG   EQU     033h                  ; Index attr: Reg pixel pan
  23. MAP_MASK        EQU     002h                  ; Index seq : write map mask
  24. READ_MAP        EQU     004h                  ; Reg lect map GIndex
  25. START_DISP_HI   EQU     00Ch                  ; CRTIndex: display start hi
  26. START_DISP_LO   EQU     00Dh                  ; CRTIndex: display start lo
  27.                               
  28. MAP_MASK_PLANE1 EQU     00102h                ; Map Register + Plane 1 
  29. MAP_MASK_PLANE2 EQU     01102h                ; Map Register + Plane 2
  30. ALL_PLANES_ON   EQU     00F02h                ; Map Register + All Bit Planes
  31.  
  32. PLANE1_ON       EQU     0102h                              
  33. PLANE2_ON       EQU     0202h                              
  34. PLANE3_ON       EQU     0402h
  35. PLANE4_ON       EQU     0802h
  36.  
  37. CHAIN4_OFF      EQU     00604h                ; Chain 4 mode Off
  38. ASYNC_RESET     EQU     00100h                ; (A)synchronous Reset
  39. SEQU_RESTART    EQU     00300h                ; Sequencer Restart
  40.                               
  41. LATCHES_ON      EQU     00008h                ; Bit Mask + Data from Latches
  42. LATCHES_OFF     EQU     0FF08h                ; Bit Mask + Data from CPU 
  43.                                                                   
  44. VERT_RETRACE    EQU     08h                   ; INPUT_1: Vertical Retrace Bit
  45. PLANE_BITS      EQU     03h                   ; Bits 0-1 of Xpos = Plane #
  46. ALL_PLANES      EQU     0Fh                   ; All Bit Planes Selected
  47. CHAR_BITS       EQU     0Fh                   ; Bits 0-3 of Character Data
  48.                               
  49. GET_CHAR_PTR    EQU     01130h                ; VGA BIOS Func: Get Char Set 
  50. ROM_8x8_Lo      EQU     03h                   ; ROM 8x8 Char Set Lo Pointer 
  51. ROM_8x8_Hi      EQU     04h                   ; ROM 8x8 Char Set Hi Pointer 
  52.                               
  53. ; ===  - Constantes propres à l'unité -  ===
  54.                               
  55. FALSE           EQU     0
  56. TRUE            EQU     -1
  57. nil             EQU     0
  58.                               
  59. SCREEN_WIDTH    EQU     80                    ; largeur en bytes
  60. SCREEN_HEIGHT   EQU     200                   ; hauteur en pixels
  61. LAST_PAGE       EQU     4                     ; # de pages
  62. PAGE_SIZE       EQU     16000                 ; taille d'une page en bytes
  63.                               
  64. ; ===  - Variables propres à l'unité -  ===
  65. MRF_TEXT ENDS
  66. _DATA2 SEGMENT
  67.                               
  68. ;PAGE_ADDR       DW      0, 16000, 32000, 48000 ; offsets de chaque page
  69. ;VISUAL_PAGE     DW      0                      ; page affichée
  70. ;ACTIVE_PAGE     DW      0                      ; page active
  71. ;CURRENT_PAGE    DW      0                      ; offset page courante
  72. CURRENT_SEGMENT DW      0                      ; segment mémoire VGA
  73. CURRENT_XOFFSET DW      0                      ; offset x actuel (display)
  74. CURRENT_YOFFSET DW      0                      ; offset y actuel (display)
  75. CURRENT_MOFFSET DW      0                      ; offset départ actuel
  76.                                                
  77. MAX_XOFFSET     DW      0                      ; maximum x offset (display)
  78. MAX_YOFFSET     DW      0                      ; maximum y offset (display)
  79.                                                
  80. CHARSET_LOW     DW      0, 0                   ; Far Ptr to Char Set:0-127
  81. CHARSET_HI      DW      0, 0                   ; Far Ptr to Char Set:128-255
  82.                                                
  83. ; ===  - variables mises dans le code segment pour accès plus facile -  ===
  84.                               
  85. _DATA2 ENDS
  86. MRF_TEXT SEGMENT
  87.                               
  88. Left_Clip_Mask  DB 0Fh, 0Eh, 0Ch, 08h
  89. Right_Clip_Mask DB 01h, 03h, 07h, 0Fh
  90.                               
  91. ; ===  - Code macros -  ===
  92.                               
  93. OUT_16 MACRO Register, Value
  94. ; Macro to OUT a 16 bit value to an I/O port
  95. IFDIFI <Register>, <DX>               ; If DX not setup
  96.     MOV             DX, Register  ; then Select Register
  97. ENDIF
  98. IFDIFI <Value>, <AX>                  ; If AX not setup 
  99.     MOV             AX, Value     ; then Get Data Value
  100. ENDIF
  101.     OUT             DX, AX        ; Set I/O Register(s)
  102. ENDM
  103.                               
  104. OUT_8 MACRO Register, Value
  105. ; Macro to OUT a 8 bit value to an I/O Port
  106. IFDIFI <Register>, <DX>               ; If DX not setup
  107.         MOV             DX, Register  ; then Select Register
  108. ENDIF
  109. IFDIFI <Value>, <AL>                  ; If AL not Setup
  110.         MOV             AL, Value     ; then Get Data Value
  111. ENDIF
  112.         OUT             DX, AL        ; Set I/O Register
  113. ENDM
  114.                               
  115. PUSHx MACRO R1, R2, R3, R4, R5, R6, R7, R8
  116. ; macros to PUSH and POP multiple registers
  117. IFNB <R1>
  118.         PUSH    R1                    ; Save R1
  119.         PUSHx   R2, R3, R4, R5, R6, R7, R8
  120. ENDIF
  121. ENDM
  122.                               
  123. POPx MACRO R1, R2, R3, R4, R5, R6, R7, R8
  124.         IFNB <R1>
  125.                 POP             R1            ; Restore R1
  126.                 POPx    R2, R3, R4, R5, R6, R7, R8
  127.         ENDIF
  128. ENDM
  129.                               
  130. CLR MACRO Register
  131. ; Macro to Clear a Register to 0
  132.         XOR             Register, Register    ; Set Register = 0
  133. ENDM
  134.                               
  135. SET_320x200 MACRO
  136. ; 320x200x256, 4 pages max
  137.  
  138.         mov     ax, mode <1,2,4,0,0>
  139.         push    ax
  140.         call    _SETVGA
  141.  
  142. ENDM
  143.                               
  144. ;PIX MACRO x, y, color
  145. ;        push    es
  146. ;        mov     ax, 0A000h
  147. ;        mov     es, ax
  148. ;        mov     di, current_page
  149. ;        mov     ax, y
  150. ;        shl     ax, 4                   ; * 80
  151. ;        mov     bx, ax
  152. ;        shl     ax, 2
  153. ;        add     ax, bx
  154. ;                                      
  155. ;        mov     bx, x
  156. ;        mov     cx, bx
  157. ;        shr     bx, 2
  158. ;        add     bx, ax                  ; offset = width*ypos + xpos/4
  159. ;        mov     ax, MAP_MASK_PLANE1
  160. ;        and     cl, PLANE_BITS
  161. ;        shl     ah, cl
  162. ;        OUT_16  SC_Index, ax            ; sélection plan
  163. ;        mov     al, color
  164. ;        mov     es:[di+bx], al          ; inscrit le pixel
  165. ;        pop     es
  166. ;ENDM
  167.                               
  168. SET_POINT PROC
  169.         push    bp
  170.         mov     bp, sp
  171.         push    fs
  172.         LSFS    _DATA, ax
  173.         push    es
  174.         mov     ax, 0A000h
  175.         mov     es, ax
  176.         mov     di, Dest                ;current_page
  177.         mov     di, word ptr fs:[di]
  178.         mov     ax, [bp+6]
  179.         shl     ax, 4                   ; * 80
  180.         mov     bx, ax
  181.         shl     ax, 2
  182.         add     ax, bx
  183.                                       
  184.         mov     bx, [bp+8]
  185.         mov     cx, bx
  186.         shr     bx, 2
  187.         add     bx, ax                  ; offset = width*ypos + xpos/4
  188.         mov     ax, MAP_MASK_PLANE1
  189.         and     cl, PLANE_BITS
  190.         shl     ah, cl
  191.         OUT_16  SC_Index, ax            ; sélection plan
  192.         mov     al, byte ptr [bp+4]
  193.         mov     es:[di+bx], al          ; inscrit le pixel
  194.         pop     es
  195.         pop     fs                      
  196.         leave
  197.         ret 6
  198. SET_POINT ENDP
  199.                               
  200. ;SET_ACTIVE_PAGE MACRO num
  201. ;        mov     ax, PAGE_ADDR[num*2]
  202. ;        mov     current_page, ax
  203. ;ENDM
  204.                               
  205. ;SET_VISUAL_PAGE MACRO num
  206. ;LOCAL WAIT0, WAITV        
  207. ;        
  208. ;wait0:                       ; wait for Sync Flag
  209. ;         cmp     _SyncFlag,1
  210. ;         jne      wait0
  211. ;         mov     _SyncFlag,0
  212. ;
  213. ;; set start display address to the new page
  214. ;                              
  215. ;        mov     dx, CRTC_Index          ; on modifie le séquenceur vga
  216. ;        mov     cx, PAGE_ADDR[num*2]
  217. ;                                      
  218. ;        mov     al, START_DISP_LO       ; display start low reg
  219. ;        mov     ah, cl                  ; low 8 bits of start addr
  220. ;        out     dx, ax                  ; set display addr low
  221. ;                                      
  222. ;        mov     al, START_DISP_HI       ; display start high reg
  223. ;        mov     ah, ch                  ; high 8 bits of start addr
  224. ;        out     dx, ax                  ; set display addr high
  225. ;                              
  226. ;ENDM
  227. COMMENT^                              
  228. HORIZONTAL_LINE PROC
  229. ; x1 / x2 / y / color        
  230.         push    bp
  231.         mov     bp, sp
  232.         cld
  233.         OUT_8   SC_INDEX, MAP_MASK
  234.         mov     si, [bp+10]
  235.         mov     di, [bp+8]
  236.         mov     ax, [bp+6]
  237.         shl     ax, 4                   ; * 80
  238.         mov     dx, ax
  239.         shl     ax, 2
  240.         add     dx, ax
  241.         mov     ax, si
  242.         and     si, PLANE_BITS
  243.         mov     bl, Left_Clip_Mask[si]
  244.         mov     cx, di
  245.         and     di, PLANE_BITS
  246.         mov     bh, Right_Clip_Mask[di]
  247.         shr     ax, 2
  248.         shr     cx, 2
  249.         mov     di, 0A000h
  250.         mov     es, di
  251.         mov     di, current_page
  252.         add     di, dx
  253.         add     di, ax
  254.         sub     cx, ax
  255.         jnz     dl_longn
  256.         and     bl, bh
  257. dl_longn:
  258.         OUT_8   SC_Data, bl
  259.         mov     al, byte ptr[bp+4]
  260.         mov     bl, al
  261.         stosb
  262.         jcxz    fin
  263.         dec     cx
  264.         jz      dl_xrseg
  265.                                       
  266. ; draw middle segments
  267.                               
  268.         OUT_8   dx, ALL_PLANES
  269.         mov     al, bl
  270.         rep     stosb
  271. dl_xrseg:
  272.         OUT_8   dx, bh
  273.         mov     al, bl
  274.         stosb
  275. fin:
  276.         leave
  277.         ret 8
  278. HORIZONTAL_LINE ENDP
  279. ^                              
  280. HLINE MACRO x1, x2, y, color
  281. ; suppose es chargé à 0A000h !
  282.         push    fs
  283.         LSFS    _DATA, ax
  284.         cld
  285.         OUT_8   SC_INDEX, MAP_MASK
  286.         mov     si, &x1
  287.         mov     di, &x2
  288.         xor     eax, eax
  289.         mov     ax, &y
  290.         
  291.         mov     dx, word ptr[Taby+eax*2]
  292.  
  293.         mov     ax, si
  294.         and     si, PLANE_BITS
  295.         mov     bl, Left_Clip_Mask[si]
  296.         mov     cx, di
  297.         and     di, PLANE_BITS
  298.         mov     bh, Right_Clip_Mask[di]
  299.         shr     ax, 2
  300.         shr     cx, 2
  301.         
  302.         mov     di, Dest            ;current_page
  303.         mov     di, word ptr fs:[di]
  304.         
  305.         add     di, dx
  306.         add     di, ax
  307.         sub     cx, ax
  308.         jnz     dl_longn
  309.         and     bl, bh
  310. dl_longn:
  311.         OUT_8   SC_DATA, bl
  312.         mov     al, color
  313.         mov     bl, al
  314.         stosb
  315.         jcxz    fin
  316.         dec    cx
  317.         jz      dl_xrseg
  318.                                       
  319. ; draw middle segments
  320.                               
  321.         OUT_8   dx, ALL_PLANES
  322.         mov     al, bl
  323.         rep     stosb
  324. dl_xrseg:
  325.         OUT_8   dx, bh
  326.         mov     al, bl
  327.         stosb
  328. fin:    pop     fs
  329. ENDM
  330.                               
  331. CLEAR_VGA_SCREEN MACRO
  332.         push    fs        
  333.         LSFS    _DATA, ax
  334.  
  335.         mov     ax, 0A000h
  336.         mov     es, ax
  337.         OUT_16  SC_Index, All_Planes_On
  338.         mov     di, Dest            ;current_page
  339.         mov     di, word ptr fs:[di]
  340.         sub     eax, eax
  341.         cld
  342.         mov     cx, PAGE_SIZE/4
  343.         rep     stosd
  344.  
  345.         pop     fs
  346. ENDM
  347.  
  348. FILL_VGA_SCREEN MACRO color
  349.         push    fs
  350.         LSFS    _DATA, ax
  351.  
  352.         mov     ax, 0A000h
  353.         mov     es, ax
  354.         OUT_16  SC_Index, All_Planes_On
  355.         mov     di, Dest ;current_page
  356.         mov     di, word ptr fs:[di]
  357.         mov     al, color
  358.         mov     ah, color
  359.         shl     eax, 16
  360.         mov     al, color
  361.         mov     ah, color
  362.         cld
  363.         mov     cx, PAGE_SIZE/4
  364.         rep     stosd
  365.  
  366.         pop     fs
  367. ENDM
  368.